/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$(document).ready(function(){  
    //LOADING POPUP  
    //Click the button event!  
    $("#createGame").click(function(){  
        //centering with css  
        positionGamePopup();  
        //load popup  
        loadGamePopup();  
    });
    //CLOSING POPUP  
    //Click the x event!  
    $("#popupGameClose").click(function(){  
        disableGamePopup();  
    });  
    //Click out event!  
    $("#backgroundPopup").click(function(){  
        disableGamePopup();  
    });
})

//SETTING UP OUR POPUP  
//0 means disabled; 1 means enabled;  
var popupGameCreateStatus = 0; 

//loading popup with jQuery magic!  
function loadGamePopup(){ 
    //loads popup only if it is disabled  
    if(popupGameCreateStatus==0){  
        $("#backgroundPopup").css({  
            "opacity": "0.7"  
        });  
        $("#backgroundPopup").fadeIn("slow");  
        $("#popupGameCreate").fadeIn("slow");  
        popupGameCreateStatus = 1;  
    }  
} 

//disabling popup with jQuery magic!  
function disableGamePopup(){  
    //disables popup only if it is enabled  
    if(popupGameCreateStatus==1){  
        $("#backgroundPopup").fadeOut("slow");  
        $("#popupGameCreate").fadeOut("slow");  
        popupGameCreateStatus = 0;  
    }  
} 

//centering popup  
function positionGamePopup(){  
    //request data for centering  
    var windowWidth = document.documentElement.clientWidth;  
    var windowHeight = document.documentElement.clientHeight;  
    var popupHeight = $("#popupGameCreate").height();  
    var popupWidth = $("#popupGameCreate").width();  
    //centering  
    $("#popupGameCreate").css({  
        "position": "absolute",  
        "top": windowHeight/2-popupHeight/2,  
        "left": windowWidth/2-popupWidth/2
    });  
    //only need force for IE6  
  
    $("#backgroundPopup").css({  
        "height": windowHeight  
    });  
}  